﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using WINBASE.Controls;
using System.Drawing;

namespace WINBASE
{
    public partial class WLCForm : DockContent
    {
        public WLCForm()
        {
        }

        public WLCForm(IContainer container)
        {
            container.Add(this);
        }

        protected override void OnActivated(EventArgs e)
        {
            ApplicationObject.ActiveForm = this;
            this.Focus();
            base.OnActivated(e);
        }

        protected override void OnShown(EventArgs e)
        {
            ApplicationObject.ActiveForm = this;
            this.Focus();
            base.OnShown(e);
        }

        protected override void OnDeactivate(EventArgs e)
        {
            ApplicationObject.ActiveForm = null;
            base.OnClosed(e);
        }

        #region Property

        private string baseControlName = "";
        public string BaseControlName
        {
            get { return baseControlName; }
            set { baseControlName = value; }
        }

        private string controlName = "";
        public string ControlName
        {
            get { return controlName; }
            set 
            {
                controlName = value;
                this.Name = value;
            }
        }

        private string controlText = "";
        public string ControlText
        {
            get { return controlText; }
            set 
            { 
                controlText = value;
                this.Text = controlText;
            }
        }

        private string formView = "";
        public string FormView
        {
            get { return formView; }
            set { formView = value; }
        }

        #endregion

        #region Method

        public void InitializeBaseData()
        {
            if (LicenseManager.UsageMode != LicenseUsageMode.Runtime) return;

            object basefrmKey = ApplicationObject.FrmModuleList.SelectedNode["ViewBaseFrmKey"];
            object frmKey = ApplicationObject.FrmModuleList.SelectedNode["ViewFrmKey"];
            object frmText = ApplicationObject.FrmModuleList.SelectedNode["ViewFrmName"];
            object viewName = ApplicationObject.FrmModuleList.SelectedNode["ViewName"];

            this.baseControlName = basefrmKey == null || Convert.IsDBNull(basefrmKey) ?
                                string.Empty : (string)basefrmKey;

            this.controlName = frmKey == null || Convert.IsDBNull(frmKey) ?
                                string.Empty : (string)frmKey;

            this.controlText = frmText == null || Convert.IsDBNull(frmText) ?
                                string.Empty : (string)frmText;

            this.formView = viewName == null || Convert.IsDBNull(viewName) ?
                                string.Empty : (string)viewName;

            this.Name = controlName;
            this.Text = controlText;
        }

        #endregion
    }
}